﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LoanProfile.ascx.cs" Inherits="CRMWeb.UserControls.LoanProfile" %>

<%--<div class="top_section">
    <a href="/Pages/AM/LoanList.aspx">List</a> >> Profile
    <div class="fr" style="text-align: right;">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-save" onclick="SaveLoanProfile()">Save</a>
        <a id="lnkAppliction" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="ApplicationProfile()">Application</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add">Up to Date</a>
    </div>
</div>--%>
<%--<div class="topform_section">
    <div class="firstform_section">
        <div class="fitem">
            <label>Account No:</label>
            <input id="txtLoanNumber" name="LoanNumber" type="text" class="easyui-validatebox" readonly="true" style="width: 180px;" />
        </div>
        <div class="fitem">
            <label>Purpose:</label>
            <select id="cmbLoanPurpose" class="easyui-combobox" data-options="panelHeight:'auto',editable:false" disabled="disabled" name="LoanPurpose" style="width: 180px;">
                <option value="Personal">Personal</option>
                <option value="Business">Business</option>
            </select>
        </div>
        <div class="fitem">
            <label>Product:</label>
            <select id="txtLoanProduct" class="easyui-combobox" data-options="panelHeight:'auto',editable:false" disabled="disabled" name="product" style="width: 180px;">
                <option value="Unsecured Business Loan">Unsecured Business Loan</option>
                <option value="Business Loan">Business Loan</option>
                <option value="Consumer Loan">Consumer Loan</option>
                <option value="Costs Recovery">Costs Recovery</option>
            </select>
        </div>
    </div>
    <div class="firstform_section">
        <div class="fitem">
            <label>Loan Status:</label>
            <select id="cmbLoanStatus" class="easyui-combobox" data-options="panelHeight:'auto',editable:false" disabled="disabled" name="LoanStatus" style="width: 150px;">
                <option value="0"></option>
                <option value="1">Pending</option>
                <option value="2">Open</option>
                <option value="3">Close</option>
            </select>
        </div>
        <div class="fitem">
            <label>Balance:</label>
            <input id="txtLoanBalance" style="width: 150px;" class="easyui-numberbox" data-options="min:0 ,precision:2" readonly="true" name="Balance" />
        </div>
        <div class="fitem">
            <label>Draw Down:</label>
            <input id="txtLoanDrowDowndate" name="draw_down_date" class="easyui-datebox" disabled="disabled" data-options="formatter:formatDate" style="width: 90px;" />
        </div>
    </div>
    <div class="firstform_section">
        <div class="fitem">
            <label>Memo:</label>
        </div>
        <textarea id="txtMemo" name="Memo" style="width: 100%; height: 50px;"></textarea>
    </div>
</div>--%>
<script type="text/javascript">
    function formatDate(value, row) {
        var date = new Date(value);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        return (d < 10 ? ('0' + d) : d) + '/' + (m < 10 ? ('0' + m) : m) + '/' + y;
    }

    function showPrompt() {
        return 'You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?';
    }

    function enableWindowUnload() {

        $('#txtMemo').change(function () {
            $('#lnkAppliction').linkbutton('disable');
            window.onbeforeunload = showPrompt;
        });
    }

    $(document).ready(function () {
        DisplayLoanProfile();
        setHeight();
        enableWindowUnload();
    });

    function DefaultformatLoanDate(value) {
        dArr = value.split('/');
        return dArr[1] + '/' + dArr[0] + '/' + dArr[2];
    }

    /*Redirect to application profile*/
    function ApplicationProfile() {
        $.ajax({
            url: '/WebServices/AM/LoanForm.ashx?method=SearchLoanDetailByLoanID',
            contentType: 'application/json; charset=utf-8',
            data: { 'LoanID': getQuerystring('LoanID', '') },
            success: function (data) {
                $.each(eval(data.replace(/[\r\n]/, '')), function (i, rec) {
                    window.location.href = "/Pages/Application/ApplicationDetail.aspx?app_id=" + rec.app_id;
                });
            }
        });
    }

    /* this statement is use to Display data */
    function DisplayLoanProfile() {
        $.ajax({
            url: '/WebServices/AM/LoanForm.ashx?method=SearchLoanDetailByLoanID',
            contentType: 'application/json; charset=utf-8',
            data: { 'LoanID': getQuerystring('LoanID', '') },
            success: function (data) {
                $.each(eval(data.replace(/[\r\n]/, '')), function (i, rec) {
                    /* set value in labels */
                    $('#txtLoanNumber').val(rec.LoanNumber);
                    $('#cmbLoanPurpose').combobox('setValue', rec.Purpose);
                    $('#txtLoanProduct').combobox('setValue', rec.Product);
                    $('#cmbLoanStatus').combobox('setValue', rec.LoanStatusID);
                    $('#txtLoanDrowDowndate').datebox('setValue', formatDate(rec.DrawDownDate, null));
                    $('#txtMemo').val(rec.Memo);
                });
            }
        });

        $.ajax({
            url: '/WebServices/AM/Repayment.ashx?method=SearchRepaymentByLoanID',
            contentType: 'application/json; charset=utf-8',
            data: { 'LoanID': getQuerystring('LoanID', '') },
            success: function (data) {
                $.each(eval(data.replace(/[\r\n]/, '')), function (i, rec) {
                    /* set value in labels */
                    $('#txtLoanBalance').numberbox('setValue', rec.Balance);
                });
            }
        });
    }

    function CurrentDate() {
        var currentDate = new Date()
        var day = currentDate.getDate()
        var month = currentDate.getMonth() + 1
        var year = currentDate.getFullYear()
        var todaydate = month + "/" + day + "/" + year;
        return todaydate;
    }

    /*Update LoanProfile*/
    function SaveLoanProfile() {
        window.onbeforeunload = null;
        /*Get Text Value*/
        var Memo = $('#txtMemo').val();
        var todaydate = CurrentDate();
        //insert record into loan table
        $.ajax({
            url: '/WebServices/AM/LoanForm.ashx?method=UpdateLoanInfo1',
            contentType: 'application/json; charset=utf-8',
            data: { 'LoanID': getQuerystring('LoanID', ''), "Memo": Memo, "EditDate": todaydate },
            success: function (data) {
                alert("Save Data Successfully");
                $('#lnkAppliction').linkbutton('enable');
            }
        });
    }

</script>
